import CryptoJS from "crypto-js";
const key = "imageStore"
export function encryptByDES(message) {
  var keyHex = CryptoJS.enc.Utf8.parse(key);
  var encrypted = CryptoJS.DES.encrypt(message, keyHex, {
    mode: CryptoJS.mode.ECB,
    padding: CryptoJS.pad.Pkcs7
  });
  return encrypted.toString();
}
//解密
export function decryptByDES(ciphertext) {
  var keyHex = CryptoJS.enc.Utf8.parse(key);
  var decrypted = CryptoJS.DES.decrypt({
    ciphertext: CryptoJS.enc.Base64.parse(ciphertext)
  }, keyHex, {
    mode: CryptoJS.mode.ECB,
    padding: CryptoJS.pad.Pkcs7
  });
  return decrypted.toString(CryptoJS.enc.Utf8);
}

// 对字符串进行编码
export function strToBase64(str){
  if(!str){
    return '';
  }
  var base64Str = Buffer.from(str).toString('base64');
  return base64Str;
}

export function base64ToStr(base64Str){
  var str = Buffer.from(base64Str,'base64').toString();
  return str;
}
